using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Boa.HD.AccesoDatos.Entidades;
using Boa.HD.Negocios;
using Boa.HD.Negocios.Servicios;
using Didsoft.Mvc.DataModel;
using Didsoft.Mvc.Controller;
using Didsoft.Mvc.DataModel.Lites;

namespace Boa.HD.Web.Controllers
{
    public class HD_DefinicionProblemaController : BaseController<HD_DefinicionProblema>
    {
	    #region interface servicios HD_DefinicionProblema

		private IHD_DefinicionProblemaNegociosServicio servicio = null;

		#endregion
		
		
		#region constructor

        public HD_DefinicionProblemaController()
        {
		    servicio = new HD_DefinicionProblemaNegocios();
            base.SetDataModelService(servicio);


            base.DropdownListStringsProp = "Nombre";
        }

        #endregion 

		

        [HttpPost]
        public JsonResult JSONGetElements()
        {
            try
            {
                List<KeyValueLite> datas = new List<KeyValueLite>();
                try
                {
                    datas = Service.ObtenerTodas().Select(c => new
                    KeyValueLite
                    {
                        DisplayText = c.Nombre,
                        Value = c.Id.ToString()
                    }).ToList();
                }
                catch
                {
                    datas = GetElementsForDropdownList();
                }


                return Json(new { Result = "OK", Options = datas });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }


        [HttpPost]
        public JsonResult JSONListaSinPadres()
        {
            try
            {
                List<KeyValueLite> datas = new List<KeyValueLite>();
                try
                {
                    datas = Service.ObtenerTodas().Where(p => p.ProblemaPadre != null).Select(c =>
                        new KeyValueLite
                        {
                            DisplayText = c.ProblemaPadre.Nombre + " - " + c.Nombre,
                            Value = c.Id.ToString()
                        }).ToList();
                }
                catch
                {
                    datas = GetElementsForDropdownList();
                }


                return Json(new { Result = "OK", Options = datas });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }

        [HttpPost]
        public JsonResult JSONListaPadres()
        {
            try
            {
                List<KeyValueLite> datas = new List<KeyValueLite>();
                try
                {
                    datas = Service.ObtenerTodas().Where(p => p.ProblemaPadre == null).Select(c =>
                        new KeyValueLite
                        {
                            DisplayText = c.Nombre,
                            Value = c.Id.ToString()
                        }).ToList();
                }
                catch
                {
                    datas = GetElementsForDropdownList();
                }


                return Json(new { Result = "OK", Options = datas });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }


        [HttpPost]
        public JsonResult JSONTipoEquipoDeAIT()
        {
            try
            {
                BOAPersonalNegocios boaNegocios = new BOAPersonalNegocios();
              
                List<KeyValueLite> datas = new List<KeyValueLite>();
                
                 datas = boaNegocios.GetTipoEquipos().Select(c =>
                        new KeyValueLite
                        {
                            DisplayText = c.NombreTipo,
                            Value = c.TipoEquipoId.ToString(),
                        }).ToList();
                 datas.Insert(0,new KeyValueLite() { DisplayText = "", Value = "0" });
                return Json(new { Result = "OK", Options = datas });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }

        public override ActionResult Index()
        {
            return RedirectToAction("FilterList");
        }

        public ActionResult AlertaProblemasPromedio(string guid)
        {
            return View(servicio.ProblemasYPromediosAtencion());
        }
    }
}

